package com.meida.module.bus.provider.service.impl;

import com.meida.common.mybatis.entity.EntityMap;
import com.meida.common.mybatis.model.ResultBody;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.common.mybatis.query.CriteriaSave;
import com.meida.common.utils.FlymeUtils;
import com.meida.module.bus.client.entity.BusUserMajor;
import com.meida.module.bus.provider.mapper.BusUserMajorMapper;
import com.meida.module.bus.provider.service.BusUserMajorService;
import com.meida.common.mybatis.base.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 用户专业接口实现类
 *
 * @author flyme
 * @date 2020-12-16
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class BusUserMajorServiceImpl extends BaseServiceImpl<BusUserMajorMapper, BusUserMajor> implements BusUserMajorService {

    @Override
    public ResultBody beforeAdd(CriteriaSave cs, BusUserMajor bum, EntityMap extra) {
        return ResultBody.ok();
    }


    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public ResultBody beforePageList(CriteriaQuery<BusUserMajor> cq, BusUserMajor bum, EntityMap requestMap) {
        cq.orderByDesc("bum.createTime");
        return ResultBody.ok();
    }

    @Override
    public ResultBody getMajors(Map params) {
        CriteriaQuery<BusUserMajor> cq = new CriteriaQuery(BusUserMajor.class);
        cq.eq("userId", params.get("userId"));
        List<BusUserMajor> list = list(cq);
        return ResultBody.ok(list);
    }
}
